package com.lqian.controller;

import java.util.List;

import javax.jws.WebParam.Mode;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lqian.pojo.Depart;
import com.lqian.pojo.Employee;
import com.lqian.service.depart.DepartService;
import com.lqian.service.emp.EmployeeServiceImpl;

@Controller
public class DepartController {

	@Autowired
	private DepartService departService;
	
	
	@RequestMapping("/departList.do")
	public String getEmployee(Model model){
		model.addAttribute("depart", departService.getAllDepart());
		return "depart.jsp";
	}
	
	
	
	@RequestMapping("/addDepart.do")
	public String addDepart(Depart depart){
		
		departService.addDepart(depart);
		
		return "redirect:/departList.do";
	}

	@RequestMapping("/updateDepart.do")
	public String updateDepart(Depart depart){
		System.out.println(depart.getDid());
		System.out.println(depart.getDname());
		System.out.println(depart.getDuty());
		return "redirect:/departList.do";
	}
	
	
	//编辑
	
	@RequestMapping("/editDepart.do")
	public String editDepart(Integer did,Model model) {
		//1.接受数据
		System.out.println(did);
		
		//2.操作数据库
		Depart depart = departService.findDepartByDid(did);
		
		//3.传递数据
		model.addAttribute("depart", depart);
		
		//4.返回视图
		return "editDepart.jsp";
	}
	
		//删除
		@RequestMapping("/deleteDepart.do")
		public String deleteDepart(Integer did) {
			
			//1.接受数据
			System.out.println(did);	
			
			//2.操作数据库
			Integer num=departService.deleteDepart(did);
			
			//3.传递数据
			
			//4.返回视图
			return "redirect:departList.do";

		}
		//恢复
		@RequestMapping("/resDepart.do")
		public String resDepart(Integer did) {
			
			//1.接受数据
			System.out.println(did);
			
			//2.操作数据库
			Integer num=departService.resDepart(did);
			
			//3.传递数据
			
			//4.返回视图
			return "redirect:departList.do";
		}
	
	
}
